//
//  ImageBntCell.m
//  diaoyuren
//
//  Created by Cheng on 16/1/20.
//  Copyright © 2016年 game. All rights reserved.
//

#import "ImageBntCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "VideoLIstModel.h"
#import "TOWebViewController.h"


#define AddSubView(view) [self.contentView addSubview:view]
#define imageHight 200
#define TitleHight 40

@interface ImageBntCell()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UILabel *title;
@property (nonatomic,strong) UILabel *primCountLab;
@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) VideoLIstModel *videoListModel;
@end

@implementation ImageBntCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor purpleColor];
        self.selectionStyle  = UITableViewCellSelectionStyleNone;
        
        _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, screen_width,0) style:UITableViewStylePlain];
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.dataSource = self;
        _tableview.delegate = self;
        _tableview.bounces = NO;
        [_tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

        [self.contentView addSubview:_tableview];
    }
            return self;
}

-(void)refreshCell{
    
    _detaiModel = _allModel.article;
    _videoListModel = _allModel.video_list;
    self.tableview.height = self.videoListModel.sub_item.count*44;
    [self.tableview reloadData];
    self.cellHeight = self.videoListModel.sub_item.count*44;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
       return  self.videoListModel.sub_item.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    VideoLIstModel *model = self.videoListModel.sub_item[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@\t点击查看",model.name];
    cell.imageView.image = [UIImage imageNamed:@"videov_play"];
    
    UIView *View = [[UIView alloc]initWithFrame:CGRectMake(0, 43.3, SCREEN_WIDTH, 0.5)];
    View.backgroundColor = linColor;
    [cell.contentView addSubview:View];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    VideoLIstModel *model = self.videoListModel.sub_item[indexPath.row];
    TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:model.url]];
    webViewController.webView.allowsInlineMediaPlayback =YES;
    webViewController.webView.mediaPlaybackRequiresUserAction =YES;
    if (_MyBlock) {
        _MyBlock(webViewController);
    }
}
@end